<?php

/**
 * Description of BaseAdminPresenter
 *
 * Copyright (c) 2011 Tomáš Holub (tomas.holub@webadvice.cz)
 * 
 * @author Tomáš Holub (tomas.holub@webadvice.cz)
 * @package OverFishCMS
 */

namespace AdminModule;

use Nette, Nette\Http\User;

class BaseAdminPresenter extends \BasePresenter {
    
    public $title = ""; 
    public $heading = "";
    protected $menuItem = "dashboard";
    
    protected function afterRender() {
        $this->template->title = $this->title;
        $this->template->heading = $this->heading;
        $this->template->activeMenuItem = $this->menuItem;

    }
    
    public function startup()
    {
        parent::startup();

        $user = $this->getUser();

        if (!$user->isLoggedIn()) {
            if ($user->getLogoutReason() === User::INACTIVITY) {
                $this->flashMessage('Uplynula doba neaktivity! Systém vás z bezpečnostních důvodů odhlásil.', 'warning');
            }

            $backlink = $this->getApplication()->storeRequest();
            $this->redirect('Auth:login', array('backlink' => $backlink));

        } else {
            //if (!$user->isAllowed($this->name, $this->action)) {
            //    $this->flashMessage('Na vstup do této sekce nemáte dostatečné oprávnění!', 'warning');
            //    $this->redirect('Auth:login');
            //}
        }
    }

    public function actionLogout()
    {
        $this->getUser()->logOut();
        $this->flashMessage('Práve jste sa odlásil z administrace.');
        $this->redirect('Auth:login');
    }
    
}

